<template v-if="isAlready">
		<div style="width: 100%;" :class="classname">
			<el-form :model="dataForm" :rules="dataForm.rules" ref="dataForm">
				<ex-drag-module v-for="element in card.modules" :model="dataForm" :modules="card.modules"
								:module="element"></ex-drag-module>
			</el-form>
		</div>
</template>

<script>

import ExDragModule from "@/views/asset/card/module/index.vue";

export default {
	name: 'cardContent',
	components: {ExDragModule},
	props: {
		card: {type: Object, default: null},//卡片信息
		dataForm: {type: Object, default: {}},//实体表单
		classname: {type: String, default: ""},//卡片信息
	},
	data() {
		return {
			isAlready: false,//数据是否准备就绪
		}
	},
	async created() {
		if (!this.card) {
			this.$message.error("卡片数据错误");
			return;
		}
		if (!this.dataForm.rules) {
			this.dataForm.rules = [];
		}
		this.isAlready = true;
	},
	mounted() {
	},
	watch: {},
	methods: {
		/**
		 * 表单验证，验证通过返回true
		 * @returns {Promise<boolean>}
		 */
		async validate() {
			return this.$refs.dataForm.validate((valid, invalidFields) => {
				if (!valid) {
          for(let prop in invalidFields){
            this.$message.error(invalidFields[prop][0].message);
            break;
          }
					// this.$message.warning({message: this.$t("common.form_invalid")});
					if (Array.isArray(this.card.tabs)) {
						let findFlag = false;
						this.card.tabs.forEach(tab => {
							if (!findFlag && Array.isArray(tab.cardStyles)) {
								tab.cardStyles.forEach(cardStyle => {
									if (!findFlag && invalidFields[cardStyle.code]) {
										this.activeName = tab.name;
										findFlag = true;
									}
								});
							}
						});
					}
				}
				return valid;
			});
		}
	}
}
</script>


